package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.TrainInfo;
import com.example.demo.service.TrainInfoService;
import com.example.demo.mapper.TrainInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【train_info】的数据库操作Service实现
* @createDate 2024-09-18 14:56:27
*/
@Service
public class TrainInfoServiceImpl extends ServiceImpl<TrainInfoMapper, TrainInfo>
    implements TrainInfoService{
    @Autowired
    TrainInfoMapper trainInfoMapper;

    @Override
    public List<TrainInfo> selectByUserId(String userId) {
        QueryWrapper<TrainInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("UserID",userId).orderByDesc("StartTime");;

        return trainInfoMapper.selectList(queryWrapper);
    }
    @Override
    public TrainInfo selectByTrainingid(String trainingId) {
        QueryWrapper<TrainInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("trainingId",trainingId);
        queryWrapper.orderByDesc("id");
        return trainInfoMapper.selectOne(queryWrapper);
    }
}




